import 'dart:convert';

import 'package:shortmovieapp/data/localData.dart';
import 'package:json_annotation/json_annotation.dart';

part 'viewData.g.dart';

enum MyPageTag {
  wander,
  recommended,
  favorites,
  me,
}

class MyPageRoute {
  static String seach = '/search';
  static String video = '/video';
  static String createMovie = '/createMovie';
  static String myMovieList = '/myMovieList';
  static String movieEdit = '/movieEdit';
}

@JsonSerializable()
class TypeMovieItems {

  @JsonKey(includeIfNull: false)
  List<MovieItemData> itemDatas;

  TypeMovieItems(this.itemDatas);
  
  factory TypeMovieItems.fromJson(Map<String, dynamic> json) => _$TypeMovieItemsFromJson(json);
  Map<String, dynamic> toJson() => _$TypeMovieItemsToJson(this);

  factory TypeMovieItems.fromJsonString(String jsonString)=>
       _$TypeMovieItemsFromJson(json.decode(jsonString));
  String toJsonString() =>  json.encode(toJson());
}

enum MovieType {
  other,
  recommond,
  fanzhuan, //反转,
  zongcai, //总裁,
  dushinaodong, //都市脑洞,
  xiandaiyanqing, //现代言情,
  tuili, //推理,
  wuxia, //武侠,
  xiangcun, //乡村
}
extension MovieTypeExtension on MovieType {
  String get stringValue {
    return this.toString().split('.').last;
  }
}


String MovieType2String(MovieType type) {
  if (type == MovieType.recommond) return "热门";
  if (type == MovieType.fanzhuan) return "反转";
  if (type == MovieType.zongcai) return "总裁";
  if (type == MovieType.dushinaodong) return "都市脑洞";
  if (type == MovieType.xiandaiyanqing) return "现代言情";
  if (type == MovieType.tuili) return "推理";
  if (type == MovieType.wuxia) return "武侠";
  if (type == MovieType.xiangcun) return "乡村";
  return "";
}
MovieType parseMovieType(String value) {
  for (MovieType movieType in MovieType.values) {
    if (movieType.stringValue == value) {
      return movieType;
    }
  }
  return MovieType.other;
}
@JsonSerializable()
class VideoData {
  @JsonKey()
  final int movieId;
  @JsonKey()
  final int episodeId;
  @JsonKey()
  final String url;
  @JsonKey()
  final String icon;
  @JsonKey()
  final String? title;
  @JsonKey()
  final String? desc;
  @JsonKey()
  final int publishedDate;
  @JsonKey()
  final bool approved;
  @JsonKey()
  final int watchTimes;
  VideoData({required this.movieId,required this.episodeId,required this.url,
  required this.icon,this.title,this.desc,required this.publishedDate,required this.approved,this.watchTimes = 0});

  factory VideoData.fromJson(Map<String, dynamic> json) => _$VideoDataFromJson(json);
  Map<String, dynamic> toJson() => _$VideoDataToJson(this);

  factory VideoData.fromJsonString(String jsonString)=>
       _$VideoDataFromJson(json.decode(jsonString));
  String toJsonString() =>  json.encode(toJson());
}

@JsonSerializable()
class MovieData {
  @JsonKey()
  final MovieItemData info;
  @JsonKey()
  final List<VideoData> videoDatas;
  MovieData(this.info,this.videoDatas);
  
  factory MovieData.fromJson(Map<String, dynamic> json) => _$MovieDataFromJson(json);
  Map<String, dynamic> toJson() => _$MovieDataToJson(this);

  factory MovieData.fromJsonString(String jsonString)=>
       _$MovieDataFromJson(json.decode(jsonString));
  String toJsonString() =>  json.encode(toJson());

  @override String toString() {
    return "$info, videos:${videoDatas.length}";
  }
}